package com.itkaien.javaeebased.multipleSystem;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Work02 extends Thread {

    public static Integer teciket = 100;
    static Lock lock = new ReentrantLock();

    @Override
    public void run() {
        sellTicker();
    }

    public void sellTicker() {
        while (teciket > 0) {
            lock.lock();
            teciket--;
            System.out.println( getName()+"销售了第" + teciket + "张票");
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                lock.unlock(); //释放锁
            }
        }
    }


}
